<?php
use yii\widgets\ActiveForm;
?>
<section class="vbox">

	<section class="scrollable padder">

		<div class="m-b-md">
			<h3 class="m-b-none"></h3>
		</div>


		<section class="panel panel-default">
			<header class="panel-heading bg-light">
				<span class="hidden-sm h5">提交上线单</span>
			</header>
			<form class="form-horizontal form-pajax form-validate" method="post"  action="<?php echo \Yii::$app->urlManager->createUrl("available/create"); ?>">
				<div class="panel-body">
					<div class="tab-content">
						<div class="tab-pane active" id="base">
							<div class="panel-body">

									<div class="form-group">
										<label class="col-sm-2 control-label">上线单标题</label>
										<div class="col-sm-3 controls" >
											<input type="text" class="form-control" data-rule-required="true" value="" name="title" >
										</div>
									</div>
									<div class="line line-dashed b-b line-lg pull-in"></div>
									<div class="form-group">
										<label class="col-sm-2 control-label">选取分支</label>
										<div class="col-sm-3 controls">
											<select name="branch" class="form-control m-b" id="branch">
												<option value="master">master</option>
											</select>
										</div>
										<label class="control-label">
											<a href="#" class="text-sm text-info show-tip"><i class="icon icon-refresh"></i></a><span class="tip text-dark" style="margin-left: 10px;display: none;">查看所有分支</span>
											<i class="get-branch icon-spinner icon-spin orange bigger-125" style="display: none"></i>
										</label>
									</div>
									<div class="line line-dashed b-b line-lg pull-in"></div>
									<div class="form-group">
										<label class="col-sm-2 control-label">版本选取</label>
										<div class="col-sm-3 controls">

											<select name="commit_id" class="form-control m-b" id="commit_id">
											</select>
										</div>
										<label class="control-label">
										</label>
									</div>
									<div class="line line-dashed b-b line-lg pull-in"></div>
									<div class="form-group">
										<label class="col-sm-2 control-label">全量/增量</label>
										<div class="col-sm-2 controls">
											<label class="checkbox-inline i-checks" data-toggle="tooltip" data-placement="top" title="全量上线所有文件, 删除不在代码仓库中的文件">
												<input type="radio" name="file_transmission_mode" class="file_transmission_mode" value="<?php echo \app\models\TaskModel::FILE_TRANSMISSION_MODE_FULL;?>" checked><i></i> 全量上线
											</label>
											<label class="checkbox-inline i-checks" data-toggle="tooltip" data-placement="top" title="指定文件列表, 只发布指定的文件和目录">
												<input type="radio" name="file_transmission_mode" class="file_transmission_mode" value="<?php echo \app\models\TaskModel::FILE_TRANSMISSION_MODE_PART;?>" ><i></i> 指定文件
											</label>
											<span class="help-block m-b-none"></span>
										</div>
									</div>

									<div class="form-group" style="display: none;" id="close">
										<div class="line line-dashed b-b line-lg pull-in"></div>
										<label class="col-sm-2 control-label">文件列表</label>
										<div class="col-sm-6 controls">
											<textarea class="form-control " rows="6" data-minwords="6" data-rule-required="true" placeholder="index.php
	README.md
	dir_name
	file*" name="file_list" id="site_close_msg" ></textarea>
										</div>
									</div>

							</div>

						</div>
					</div>
				</div>
				<footer class="panel-footer text-right bg-light lter">
					<input name="id" value="<?php echo $project['id'];?>" type="hidden"/>
					<button type="reset" class="btn btn-default btn-s-xs">重置</button>
					<button type="submit" class="btn btn-success btn-s-xs">保存</button>
				</footer>
			</form>
		</section>
	</section>
</section>
<!-- 错误提示-->
<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content" style="800px">
			<div class="modal-header">
				<button type="button" class="close"
						data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					发生了错误                    </h4>
			</div>
			<div class="modal-body"></div>
		</div><!-- /.modal-content -->
	</div>

</div>
<script>


	function getBranchList() {
		$('.get-branch').show();
		$('.tip').hide();
		$('.show-tip').hide();
		var project_id = "<?php echo $project['id'];?>";
		$.get("/application/get-branch?id=" + project_id, function (msgObj) {
//			// 获取分支失败
			$('#branch').html(msgObj);
			$('.get-branch').hide();
			$('.show-tip').show();
			$('#branch').change();
		});
	}

</script>
<script>
	$(document).ready(function() {
		$(".file_transmission_mode").click(function() {
			var val = $(this).val();
			if(val == 1) {
				$("#close").hide();
			} else {
				$("#close").show();
			}
		});

		// 查看所有分支提示
		$('.show-tip')
				.hover(
						function() {
							$('.tip').show()
						},
						function() {
							$('.tip').hide()
						})
				.click(function() {
					getBranchList();
				});

		$('#branch').change(function() {
			getCommitList();
		});

	});



	function getCommitList() {
		$('.get-history').show();
		var project_id = "<?php echo $project['id'];?>";
		$.get("/application/get-commit-history?id=" + project_id +"&branch=" + $('#branch').val(), function (msgObj) {
			$('#commit_id').html(msgObj);
			$('.get-history').hide()
		});
	}


	// 页面加载完默认拉取master的commit log
	getCommitList();
</script>
